﻿function setCookie(name, value)
{
    var  expdate  =  new  Date();
    var  argv  =  setCookie.arguments;
    var  argc  =  setCookie.arguments.length;
    var  expires  =  (argc  >  2)  ?  argv[2]  :  null;
    var  path  =  (argc  >  3)  ?  argv[3]  :  null;
    var  domain  =  (argc  >  4)  ?  argv[4]  :  null;
    var  secure  =  (argc  >  5)  ?  argv[5]  :  false;
    if(expires!=null)  expdate.setTime(expdate.getTime()  +  (  expires  *  1000  ));
    document.cookie  =  name  +  "="  +  escape  (value)  +((expires  ==  null)  ?  ""  :  (";  expires="+  expdate.toGMTString()))
        +((path  ==  null)  ?  ""  :  (";  path="  +  path))  +((domain  ==  null)  ?  ""  :  (";  domain="  +  domain))
        +((secure  ==  true)  ?  ";  secure"  :  "");
}

function getCookie(name){ 
  var a=document.cookie.split("; "); 
  name+="="; 
  for(var i=0;i<a.length;i++) 
    if(a[i].indexOf(name)==0) 
      return unescape(a[i].substr(name.length)); 
  return ""; 
  
  }
function  delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime()-1);
    var cval = getCookie(name);
    var  argv  =  delCookie.arguments;
    var  argc  =  delCookie.arguments.length;
    var  path  =  (argc  >  1)  ?  argv[1]  :  null;
    var  domain  =  (argc  >  2)  ?  argv[2]  :  null;
    var  secure  =  (argc  >  3)  ?  argv[3]  :  false;
    
    document.cookie = name + "=" + escape(cval) + "; Expires="+ exp.toGMTString()
        +((path  ==  null)  ?  ""  :  (";  path="  +  path))  +((domain  ==  null)  ?  ""  :  (";  domain="  +  domain))
        +((secure  ==  true)  ?  ";  secure"  :  "");
}